Skip to content

Rework SolutionLoader#3701

Open
michaelbynum wants to merge 23 commits intoPyomo:mainfrom
michaelbynum:solver_api
Open

Rework SolutionLoader#3701
michaelbynum wants to merge 23 commits intoPyomo:mainfrom
michaelbynum:solver_api

Conversation

@michaelbynum
Copy link
Contributor

Summary/Motivation:

This PR updates the solution loader in pyomo/contrib/solver based on recent design discussions.

Changes proposed in this PR:

  • add get_number_of_solutions method
  • add get_solution_ids method
  • add load_solution_method
  • add load_import_suffixes method
  • add solution_id as an argument to methods

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

@michaelbynum michaelbynum changed the title Rework SolutionLoader [Depends on #3698] Rework SolutionLoader Aug 13, 2025
@codecov
Copy link

codecov bot commented Aug 14, 2025

Codecov Report

❌ Patch coverage is 76.61290% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.72%. Comparing base (2a9f2a0) to head (7557036).

Files with missing lines Patch % Lines
pyomo/contrib/solver/solvers/asl_sol_reader.py 66.66% 7 Missing ⚠️
pyomo/contrib/solver/common/solution_loader.py 86.66% 6 Missing ⚠️
...ontrib/solver/solvers/gurobi/gurobi_direct_base.py 64.70% 6 Missing ⚠️
pyomo/contrib/solver/solvers/highs.py 64.28% 5 Missing ⚠️
...contrib/solver/solvers/gurobi/gurobi_persistent.py 71.42% 4 Missing ⚠️
pyomo/contrib/solver/solvers/ipopt.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3701      +/-   ##
==========================================
- Coverage   89.73%   89.72%   -0.02%     
==========================================
  Files         904      904              
  Lines      105871   105946      +75     
==========================================
+ Hits        95007    95057      +50     
- Misses      10864    10889      +25     
Flag Coverage Δ
builders 29.03% <34.67%> (+<0.01%) ⬆️
default 83.83% <66.93%> (?)
expensive 35.50% <34.67%> (?)
linux 86.82% <76.61%> (-2.66%) ⬇️
linux_other 86.82% <76.61%> (-0.02%) ⬇️
oldsolvers 29.87% <34.67%> (+<0.01%) ⬆️
osx 82.99% <76.61%> (-0.02%) ⬇️
win 85.06% <76.61%> (-0.01%) ⬇️
win_other 85.06% <76.61%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@blnicho blnicho removed this from Pyomo 6.10 Feb 4, 2026
@michaelbynum michaelbynum changed the title [Depends on #3698] Rework SolutionLoader Rework SolutionLoader Feb 11, 2026
Copy link
Member

@jsiirola jsiirola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple minor questions that don't need to hold up the PR and one significant one that probably does (it look like the ASL solution loader is not loading all import suffixes).

Comment on lines +35 to +36
for k, v in solution_loader.get_duals(solution_id=solution_id).items():
dual_suffix[k] = v
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some questions:

  • Should the Suffix be cleared before loading?
  • Could this just be:
Suggested change
for k, v in solution_loader.get_duals(solution_id=solution_id).items():
dual_suffix[k] = v
dual_suffix.update(solution_loader.get_duals(solution_id=solution_id))

vars_to_load: list
A list of the variables whose solution value should be retrieved. If vars_to_load
is None, then the values for all variables will be retrieved.
solution_id: Optional[Any]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of Optional[Type], I believe the current "preferred Python" annotation is Type | None. In this case, since Any includes None, I think you could just do Any (although Any | None is a little more explicit).

Comment on lines +76 to +77
def load_import_suffixes(self, solution_id=None):
load_import_suffixes(self._pyomo_model, self, solution_id=solution_id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only loads duals and rc ... the ASL supports arbitrary inpirt suffixes, which I think need to be supported here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give me an example of what ASLSolFileData would look like if it had other suffixes. I see that it has attributes like var_suffixes. I assume the keys are the names of the suffixes, and the values map the variable indices to the suffix values? Any suggestions on how to test this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes: Suffix data comes back from the ASL flagged for "variables", "constraints", "objectives", and the "problem". We blindly parse that into the corresponding attributes (var_suffixes, etc).

  • For var, con, and obj, the dict maps suffix name to a dict that maps the 0-based integer index of the relevant variable / constraint / objective in the corresponding list in the NLWriterInfo returned by the writer tot he suffix value.
  • For the problem, since there is only one problem, the problem_suffixes dict just maps suffix name to value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants